package com.rabbits.tool.storage;

import android.content.Context;

import java.util.Set;

public class StorageSingleton {

    private static volatile StorageSingleton instance = null;
    private SharedPrefUtils sharedPrefUtils = null;

    private StorageSingleton(Context ctx) {
        sharedPrefUtils = new SharedPrefUtils(ctx, "storage_config");
    }

    public static StorageSingleton getInstance(Context ctx) {
        if (instance == null) {
            synchronized (StorageSingleton.class) {
                if (instance == null) {
                    instance = new StorageSingleton(ctx);
                }
            }
        }
        return instance;
    }



    public void putString(String name, String value) {
        sharedPrefUtils.putString(name, value);
    }
    public void putStringWithCommit(String name, String value) {
        sharedPrefUtils.putString(name, value);
        sharedPrefUtils.commit();
    }
    public String getString(String name, String defaultValue) {
        return sharedPrefUtils.getString(name, defaultValue);
    }



    public void putInt(String name, int value) {
        sharedPrefUtils.putInt(name, value);
    }
    public void putIntWithCommit(String name, int value) {
        sharedPrefUtils.putInt(name, value);
        sharedPrefUtils.commit();
    }
    public int getInt(String name, int defaultValue) {
        return sharedPrefUtils.getInt(name, defaultValue);
    }



    public void putFloat(String name, float value) {
        sharedPrefUtils.putFloat(name, value);
    }
    public void putFloatWithCommit(String name, float value) {
        sharedPrefUtils.putFloat(name, value);
        sharedPrefUtils.commit();
    }
    public float getFloat(String name, float defaultValue) {
        return sharedPrefUtils.getFloat(name, defaultValue);
    }



    public void putLong(String name, long value) {
        sharedPrefUtils.putLong(name, value);
    }
    public void putLongWithCommit(String name, long value) {
        sharedPrefUtils.putLong(name, value);
        sharedPrefUtils.commit();
    }
    public long getLong(String name, long defaultValue) {
        return sharedPrefUtils.getLong(name, defaultValue);
    }



    public void putBoolean(String name, boolean value) {
        sharedPrefUtils.putBoolean(name, value);
    }
    public void putBooleanWithCommit(String name, boolean value) {
        sharedPrefUtils.putBoolean(name, value);
        sharedPrefUtils.commit();
    }
    public boolean getBoolean(String name, boolean defaultValue) {
        return sharedPrefUtils.getBoolean(name, defaultValue);
    }



    public void putStringSet(String name, Set<String> value) {
        sharedPrefUtils.putStringSet(name, value);
    }
    public void putStringSetWithCommit(String name, Set<String> value) {
        sharedPrefUtils.putStringSet(name, value);
    }
    public Set<String> getStringSet(String name, Set<String> defaultValue) {
        return sharedPrefUtils.getStringSet(name, defaultValue);
    }



    public void clear() {
        sharedPrefUtils.clear();
    }
    public void removeCache(String name) {
        sharedPrefUtils.removeCache(name);
    }
    public void commit() {
        sharedPrefUtils.commit();
    }


}
